import {util} from '../../utils/util'
let app = getApp();

Page({
    data: {
        // fatherName:'',
        // sonName:'',
        oneArray: [
            {id: 0, type: 1, name: '思想品德',}, {id: 1, type: 2, name: '学业水平',}, {id: 2, type: 3, name: '身心健康',}, {
                id: 3,
                type: 4,
                name: '艺术素养',
            }, {id: 4, type: 5, name: '社会实践',}, {id: 5, type: 6, name: '特色项目',},
        ],
        twoArray: [
            {id: 0, type: 110, name: '党团活动',}, {id: 1, type: 111, name: '社团活动',}, {
                id: 2,
                type: 112,
                name: '公益劳动',
            }, {id: 3, type: 113, name: '志愿服务',}, {id: 4, type: 114, name: '个人荣誉',}, {
                id: 5,
                type: 115,
                name: '不良记录',
            }, {id: 6, type: 116, name: '其他',},
        ],
        threeArray: [
            {id: 0, type: 210, name: '研究性学习',}, {id: 1, type: 211, name: '创新成果',}, {
                id: 2,
                type: 212,
                name: '优势学科竞赛',
            }, {id: 3, type: 213, name: '其他知识竞赛',}, {id: 4, type: 214, name: '考试成绩',}, {id: 5, type: 215, name: '其他',},
        ],
        fourArray: [
            {id: 0, type: 310, name: '体育竞赛',}, {id: 1, type: 311, name: '体育社团',}, {
                id: 2,
                type: 312,
                name: '特长项目',
            }, {id: 3, type: 313, name: '基本情况',}, {id: 4, type: 314, name: '体质测试结果',}, {id: 5, type: 315, name: '其他',}
        ],
        fivesArray: [
            {id: 0, type: 410, name: '艺术比赛',}, {id: 1, type: 411, name: '艺术团队',}, {
                id: 2,
                type: 412,
                name: '特长项目',
            }, {id: 3, type: 413, name: '其他',}
        ],
        sixArray: [
            {id: 0, type: 510, name: '社会实践',}, {id: 1, type: 511, name: '研学旅行',}
        ],
        sevenArray: [
            {id: 0, type: 610, name: '其他特色项目',},
        ],
        oneIndex: 0,
        twoIndex: 0,
        threeIndex: 0,
        fourIndex: 0,
        fivesIndex: 0,
        sixIndex: 0,
        sevenIndex: 0,
        //true 显示   false 隐藏
        hide: 0,
        //true 显示   false 隐藏
        js: 2,
        //调用服务器返回的图片地址
        honorFiles: [],
        //默认图片数量
        cot: 9,
    },

    oneBindObjPickerChange(e) {
        console.log('1picker发送选择改变，携带值为', e.detail.value);
        wx.setStorageSync("honorFiles", []);
        if (e.detail.value == 5) {
            this.setData({
                oneIndex: e.detail.value,
                hide: e.detail.value,
                js: 1,
                honorFiles: [],
            });
        } else {
            this.setData({
                oneIndex: e.detail.value,
                hide: e.detail.value,
                js: 2,
                honorFiles: [],
            });
        }
    },
    twoBindObjPickerChange(e) {
        console.log('2picker发送选择改变，携带值为', e.detail.value);
        wx.setStorageSync("honorFiles", []);
        if (e.detail.value == 5) {
            this.setData({
                twoIndex: e.detail.value,
                js: 1,
                honorFiles: [],
            });
        } else {
            this.setData({
                twoIndex: e.detail.value,
                js: 2,
                honorFiles: [],
            });
        }

    },
    threeBindObjPickerChange(e) {
        console.log('3picker发送选择改变，携带值为', e.detail.value);
        wx.setStorageSync("honorFiles", []);
        if (e.detail.value == 4) {
            this.setData({
                threeIndex: e.detail.value,
                js: 1,
                honorFiles: [],
            });
        } else {
            this.setData({
                threeIndex: e.detail.value,
                js: 2,
                honorFiles: [],
            });
        }
    },
    fourBindObjPickerChange(e) {
        console.log('4picker发送选择改变，携带值为', e.detail.value);
        wx.setStorageSync("honorFiles", []);
        if (e.detail.value == 3) {
            this.setData({
                fourIndex: e.detail.value,
                js: 1,
                honorFiles: [],
            });
        } else if (e.detail.value == 4) {
            this.setData({
                fourIndex: e.detail.value,
                js: 1,
                honorFiles: [],
            });
        } else {
            this.setData({
                fourIndex: e.detail.value,
                js: 2,
                honorFiles: [],
            });
        }
    },
    fivesBindObjPickerChange(e) {
        console.log('5picker发送选择改变，携带值为', e.detail.value);
        wx.setStorageSync("honorFiles", []);
        this.setData({
            fivesIndex: e.detail.value,
            js: 2,
            honorFiles: [],
        });
    },
    sixBindObjPickerChange(e) {
        console.log('6picker发送选择改变，携带值为', e.detail.value);
        wx.setStorageSync("honorFiles", []);
        this.setData({
            sixIndex: e.detail.value,
            js: 2,
            honorFiles: [],
        });
    },
    sevenBindObjPickerChange(e) {
        wx.setStorageSync("honorFiles", []);
        this.setData({
            sevenIndex: e.detail.value,
            js: 1,
            honorFiles: [],
        });
    }, /**
     * 写实材料上传图片方法
     */
    xsuploads: function () {
        let that = this;
            wx.chooseImage({
                count: 9 - that.data.honorFiles.length, // 默认9
                //巨坑 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
                success(res) {
                    /**
                     * 上传完成后把文件上传到正式服务器  9-that.data.honorFiles.length
                     */
                    util.showLoading();
                    var honorFiles = that.data.honorFiles;
                    let tempFilePathsLength = res.tempFilePaths.length;
                    //上传多张文件
                    for (var i = 0, j = 0; i < res.tempFilePaths.length; i++) {
                        util.uploadFile(res.tempFilePaths[i]).then(function (res) {
                            honorFiles.push(
                                res
                            );
                            that.setData(that.data);
                            wx.setStorageSync("honorFiles", honorFiles);
                            if (j == tempFilePathsLength - 1) {
                                util.hideLoading();
                            }
                            j++;
                        });
                    }

            },
                fail:() =>
                {
                    util.showError('取消');
                }
            })
    },

    /**
     * 写实预览图片方法
     */
    doubleClick: function (e) {
        let index = e.target.dataset.index;
        let that = this;
        console.log(that.data.honorFiles[index]);
        console.log(that.data.honorFiles);
        wx.previewImage({
            current: that.data.honorFiles[index],
            urls: that.data.honorFiles,
            //这根本就不走
            success: function (res) {
                //console.log(res);
            },
            //也根本不走
            fail: function () {
                //console.log('fail')
            }
        })
    },
    /**
     * 长按删除图片
     */
    deleteImage: function (e) {
        var that = this;
        var honorFiles = that.data.honorFiles;
        var index = e.currentTarget.dataset.index;//获取当前长按图片下标
        wx.showModal({
            title: '提示',
            content: '确定要删除此图片吗？',
            success: function (res) {
                if (res.confirm) {
                    console.log('点击确定了');
                    honorFiles.splice(index, 1);
                } else if (res.cancel) {
                    console.log('点击取消了');
                    return false;
                }
                wx.setStorageSync('honorFiles', honorFiles)
                that.setData({
                    honorFiles,
                });
            }
        })
    },


    // 下一步
    on_nextStep() {
        let me = this;
        if (me.data.honorFiles.length == 0) {
            util.showError('请上传写实材料')
        } else {
            //获取大项实例type
            let activityType = me.data.oneArray[me.data.oneIndex].type;

            //获取小项实例type
            var instanceType = 0;

            var index = me.data.oneIndex;

            if (index == 0) {
                var ind = me.data.twoIndex;
                instanceType = me.data.twoArray[ind].type;
                if (ind == 0) {
                    //思想品德中  党团活动，社团活动 相同
                    wx.navigateTo({
                        url: '/pages/xssb/sxpd/from-sxdt/from-sxdt?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })
                } else if (ind == 1) {
                    //思想品德中  党团活动，社团活动 相同
                    wx.navigateTo({
                        url: '/pages/xssb/sxpd/from-sxdt/from-sxdt?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })
                } else if (ind == 2) {

                    //公益劳动
                    wx.navigateTo({
                        url: '/pages/xssb/sxpd/from-gyhd/from-gyhd?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })

                } else if (ind == 3) {

                    //志愿服务
                    wx.navigateTo({
                        url: '/pages/xssb/sxpd/from-zyfw/from-zyfw?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })

                } else if (ind == 4) {

                    //个人荣誉
                    wx.navigateTo({
                        url: '/pages/xssb/sxpd/from-grry/from-grry?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })

                } else if (ind == 5) {

                    //不良记录
                    wx.navigateTo({
                        url: '/pages/xssb/sxpd/from-bljl/from-bljl?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })

                } else if (ind == 6) {

                    //其它
                    wx.navigateTo({
                        url: '/pages/xssb/sxpd/from-other/from-other?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })

                }
            } else if (index == 1) {
                var ind = me.data.threeIndex;
                instanceType = me.data.threeArray[ind].type;
                if (ind == 0) {
                    //学业水平中   研究性学习
                    wx.navigateTo({
                        url: '/pages/xssb/xysp/xysp-yjxxx/xysp-yjxxx?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })
                } else if (ind == 1) {
                    //创新成果
                    wx.navigateTo({
                        url: '/pages/xssb/xysp/xysp-cxcg/xysp-cxcg?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })
                } else if (ind == 2) {

                    //优势学科竞赛
                    wx.navigateTo({
                        url: '/pages/xssb/xysp/xysp-ysxkjs/xysp-ysxkjs?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })

                } else if (ind == 3) {

                    //其它知识竞赛
                    wx.navigateTo({
                        url: '/pages/xssb/xysp/xysp-qtzsjs/xysp-qtzsjs?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })

                } else if (ind == 4) {

                    //考试成绩
                    wx.navigateTo({
                        url: '/pages/xssb/xysp/xysp-kscj/xysp-kscj?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })

                } else if (ind == 5) {

                    //其它
                    wx.navigateTo({
                        url: '/pages/xssb/xysp/xysp-qt/xysp-qt?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })

                }
            } else if (index == 2) {
                var ind = me.data.fourIndex;
                instanceType = me.data.fourArray[ind].type;

                if (ind == 0) {
                    //身心健康中   体育竞赛
                    wx.navigateTo({
                        url: '/pages/xssb/sxjk/tyjs/tyjs?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })
                } else if (ind == 1) {
                    //体育社团
                    wx.navigateTo({
                        url: '/pages/xssb/sxjk/tyst/tyst?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })
                } else if (ind == 2) {

                    //特长项目
                    wx.navigateTo({
                        url: '/pages/xssb/sxjk/tytc/tytc?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })

                } else if (ind == 3) {

                    //基本情况
                    wx.navigateTo({
                        url: '/pages/xssb/sxjk/jbqk/jbqk?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })

                } else if (ind == 4) {

                    //体质测试
                    wx.navigateTo({
                        url: '/pages/xssb/sxjk/tcjg/tcjg?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })

                } else if (ind == 5) {

                    //其它
                    wx.navigateTo({
                        url: '/pages/xssb/sxjk/qt/qt?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })

                }

            } else if (index == 3) {
                var ind = me.data.fivesIndex;
                instanceType = me.data.fivesArray[ind].type;
                if (ind == 0) {
                    //艺术素养中   艺术比赛
                    wx.navigateTo({
                        url: '/pages/xssb/yssy/ysbs/ysbs?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })
                } else if (ind == 1) {
                    //艺术团队
                    wx.navigateTo({
                        url: '/pages/xssb/yssy/ystd/ystd?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })
                } else if (ind == 2) {

                    //特长项目
                    wx.navigateTo({
                        url: '/pages/xssb/yssy/ystc/ystc?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })

                } else if (ind == 3) {

                    //其它
                    wx.navigateTo({
                        url: '/pages/xssb/yssy/qt/qt?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })

                }
            } else if (index == 4) {
                var ind = me.data.sixIndex;
                instanceType = me.data.sixArray[ind].type;
                if (ind == 0) {
                    //社会实践中   社会实践
                    wx.navigateTo({
                        url: '/pages/xssb/shsj/from-shsj/from-shsj?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })
                } else if (ind == 1) {
                    //研学旅行
                    wx.navigateTo({
                        url: '/pages/xssb/shsj/from-yxlx/from-yxlx?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })
                }
            } else if (index == 5) {
                var ind = me.data.sevenIndex;
                instanceType = me.data.sevenArray[ind].type;
                if (ind == 0) {
                    //特色项目
                    wx.navigateTo({
                        url: '/pages/xssb/tsxm/from-tsjy/from-tsjy?activityType=' + activityType + '&instanceType=' + instanceType + '&honorFiles=' + me.data.honorFiles
                    })
                }
            }
        }
    },


    onLoad(query) {
        // 页面加载
        console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
        wx.setStorageSync("honorFiles", []);
        this.setData({
            honorFiles: [],
        })
        if (query.type == 5) {
            this.setData({
                hide: query.type,
                oneIndex: query.type,
                js: 1
            });

        } else {
            this.setData({
                hide: query.type,
                oneIndex: query.type,
            });

        }


    },
    onReady() {
        // 页面加载完成
    },
    onShow() {
        // 页面显示
        var honorFiles = wx.getStorageSync("honorFiles");
        this.setData({
            honorFiles: honorFiles,
        })

    },
    onHide() {
        // 页面隐藏

    },
    onUnload() {
        // 页面被关闭
        console.log("guanbi")
    },
    onTitleClick() {
        // 标题被点击
    },
    onPullDownRefresh() {
        // 页面被下拉
    },
    onReachBottom() {
        // 页面被拉到底部
    },
    onShareAppMessage() {
        // 返回自定义分享信息
        return {
            title: 'My App',
            desc: 'My App description',
            path: 'pages/index/index',
        };
    },
});
